//
//  UIUtil.m
//  FJOSS
//
//  Created by 宇舟 高 on 12-4-25.
//  Copyright (c) 2012年 FSTI. All rights reserved.
//

#import "UIUtil.h"
#import "MBProgressHUD.h"

@implementation UIUtil

+ (void)alertOKWithTitle:(NSString *)title withMsg:(NSString *)msg withDelegate:(id)delegate
{
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title message:msg delegate:delegate cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [alertView show];
}

+ (void)alertOKCancelWithTitle:(NSString *)title withMsg:(NSString *)msg withDelegate:(id)delegate
{
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title message:msg delegate:delegate cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    [alertView show];
}

+ (UIButton *)buttonWithTitle:(NSString *)title
                            target:(id)target
                          selector:(SEL)selector
                             frame:(CGRect)frame
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
	button.frame = frame;
	button.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
	button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
	button.titleLabel.lineBreakMode = UILineBreakModeCharacterWrap;
    button.backgroundColor = [UIColor clearColor];
    
	[button setTitle:title forState:UIControlStateNormal];
    [button addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];
	return button;
}

+ (void)showToastWithText:(NSString *)text withView:(UIView *)view withDelay:(double)seconds
{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.mode = MBProgressHUDModeText;
    hud.labelText = text;
    hud.margin = 10.f;
    hud.yOffset = 150.f;
    hud.removeFromSuperViewOnHide = YES;
    [hud hide:YES afterDelay:1];
}

@end
